﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Windows.Forms;
namespace Constructor
{    
    [System.AttributeUsage(System.AttributeTargets.Method)]
    public class FrameFunction : System.Attribute { }
    public static class FunctionControler
    {
        public static List<string> ListMethods(Type method_type)
        {
            List<string> result = new List<string>();
            Type t = typeof(FunctionControler);
            MethodInfo[] info = t.GetMethods();
            foreach (MethodInfo mi in info)
            {
                bool boo = false;
                int i = 0;
                object[] atrs = mi.GetCustomAttributes(false);
                while (i < atrs.Length && !boo)
                {
                    boo = atrs[i].GetType() == typeof(FrameFunction);
                    i++;
                }               
                if (boo && mi.ReturnType == method_type)                                            
                        result.Add(mi.Name);                    
            }
            return result;
        }
        [FrameFunction]
        public static int Удалить_с_поля(Frame f1)
        {

            return -1;
        }
        [FrameFunction]
        public static int Расстояние(Frame f1, Frame f2)
        {

            return -1;
        }
        [FrameFunction]
        public static int Конец_игры()
        {

            return -1;
        }
        [FrameFunction]
        public static int КлеткаX(Frame f1)
        {

            return -1;
        }
        [FrameFunction]
        public static int КлеткаY(Frame f1)
        {

            return -1;
        }
        [FrameFunction]
        public static int КоличествоВрагов(Frame f1)
        {

            return -1;
        }
        [FrameFunction]
        public static int КоличествоВоинов(Frame f1)
        {

            return -1;
        }
        public static MethodInfo GetMethod(string method)
        {
            Type t = typeof(FunctionControler);
            return t.GetMethod(method);            
        }
        public static List<ParameterInfo> GetParameters(string method)
        {
            Type t = typeof(FunctionControler);
            if (t.GetMethod(method) != null)
                return t.GetMethod(method).GetParameters().ToList();
            return new List<ParameterInfo>();
        }
        public static void Caller(string name, object[] param)
        {
            Type t = typeof(FunctionControler);
            MethodInfo m = t.GetMethod(name);
            if (m != null)
                m.Invoke(null, param);
        }
    }
}
